package com.wencst.generateJPA;

import java.util.List;

import com.alibaba.fastjson.JSONObject;
import com.wencst.generateJPA.bean.TableBean;
import com.wencst.generateJPA.builder.IBuilder;
import com.wencst.generateJPA.builder.java.impl.ControllerBuilder;
import com.wencst.generateJPA.builder.java.impl.DaoBuilder;
import com.wencst.generateJPA.builder.java.impl.DomainBuilder;
import com.wencst.generateJPA.builder.java.impl.ServiceBuilder;
import com.wencst.generateJPA.builder.json.impl.MenuBuilder;
import com.wencst.generateJPA.builder.web.impl.DataPageBuilder;
import com.wencst.generateJPA.builder.web.impl.DetailPageBuilder;
import com.wencst.generateJPA.builder.web.impl.ListPageBuilder;
import com.wencst.generateJPA.config.CoreContext;
import com.wencst.generateJPA.database.IDatabase;
import com.wencst.generateJPA.database.impl.DefaultDB;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public class RunBuild {
	public static void build(CoreContext coreContext) {
		IDatabase db = new DefaultDB(coreContext);
		List<TableBean> ltb = db.getAllTables();
		IBuilder ib = null;
		for (TableBean tb : ltb) {
			coreContext.setTb(tb);
			ib = new DomainBuilder(coreContext);
			ib.build();
			ib = new DaoBuilder(coreContext);
			ib.build();
			ib = new ServiceBuilder(coreContext);
			ib.build();
			ib = new ControllerBuilder(coreContext);
			ib.build();
			ib = new ListPageBuilder(coreContext);
			ib.build();
			ib = new DataPageBuilder(coreContext);
			ib.build();
			ib = new DetailPageBuilder(coreContext);
			ib.build();
			ib = new MenuBuilder(coreContext);
			ib.build();
			log.info("finish build {} \n JsonObject:{}"
					,tb.getTableName()
					,JSONObject.toJSONString(tb));
		}
	}
}
